/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agtranscontinental.sisref.sessionbean;

import com.agtranscontinental.sisref.dto.DanioDto;
import com.agtranscontinental.sisref.model.Danio;
import com.agtranscontinental.sisref.sessionremote.DanioEjbRemote;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author ericson
 */
@Stateless
public class DanioEjbBean implements DanioEjbRemote {

    @PersistenceContext(unitName = "sisref_pu")
    private EntityManager emSisref;

    @Override
    public List<DanioDto> getDanioLst() {
        List<DanioDto> danioDtoLst = null;
        try {
            Query q = emSisref.createNamedQuery("Danio.findAll");
            List<Danio> dLst = (List<Danio>) q.getResultList();
            if(dLst!=null && !dLst.isEmpty()){
                danioDtoLst = new ArrayList<DanioDto>();
                for(Danio d : dLst){
                    danioDtoLst.add(d.toDanioDto());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return danioDtoLst;
    }

}
